import './App.css';
import { useState, useEffect } from 'react';
import Header from './components/Header';
import Body from './components/Body';
import Input from './components/Input';
const { electron: { ipcRenderer: ipc } } = window;
function App() {
  const [path, setPath] = useState('')
  const [tip, setTip] = useState(true)
  const onClickPath = () => {
    setTip(false)
  }
  function onConfirm(tip) {
    if (tip) {
      setPath(tip)
      setTip(true)
      ipc.send('write-path', tip)
    }
  }
  useEffect(() => {
    ipc.send('initial-path-request', null)
    ipc.on('initial-path-response', (event, arg) => {
      setPath(arg)
    })
  }, [setPath])

  return (
    <div>
      {(!!path && tip) || <Input inputTip={path} onClick={onConfirm} />}
      <Header path={path} onClick={onClickPath} />
      <Body />
    </div>
  )
}

export default App;
